<?php
  require_once('library.php');
  // Check if the container has childs
  $sql = 'SELECT id FROM `containers` WHERE parentId = ?';
  $result = $dbRead->fetchAll($sql,$_GET['id']);
  $size_of_result = sizeof($result);
  if ($size_of_result == 0){
	  $sql = 'SELECT itemId FROM `items` WHERE containerId = ?';
	  $result = $dbRead->fetchAll($sql,$_GET['id']);
	  $size_of_result = sizeof($result);
	  if ($size_of_result == 0){ 
	     // The container has no childs
	     $dbWrite->delete('containers','id='.$_GET['id']);
	     header('Location: ../DBMain.php?id='.$_GET['parentId'].'&dbId='.$_GET['dbId'].'&name='.$_GET['parentName']);
		 break;
	  }
  }
  // There are childs, do not delete
  header('Location: ../DBMain.php?id='.$_GET['parentId'].'&dbId='.$_GET['dbId'].'&name='.$_GET['parentName'].'&msg=ContainerNotEmpty');
?>
